package com.jidolstar.astro
{
	/**
	 * 달력값을 나타내는 클래스 
	 * @author Yongho,Ji (jidolstar@gmail.com)
	 * @since 2009.04.06
	 */ 
	public class ALCalendarDate
	{
		private var _year:int;
		private var _month:int;
		private var _day:int;
		private var _hour:int;
		private var _minute:int;
		private var _second:Number;
		private var _fractionalHour:Number;
		private var isSetFractionalHour:Boolean = false;
		 
		public function ALCalendarDate( year:int, month:int, day:int, hour:int = 0, minute:int = 0, second:Number = 0)
		{
			this._year = year;
			this._month = month;
			this._day = day;
			this._hour = hour;
			this._minute = minute;
			this._second = second;	
		}
		
		public function get year():int
		{
			return _year;
		}
		
		public function get month():int
		{
			return _month;
		}
		
		public function get day():int
		{
			return _day;
		}
		
		public function get hour():int
		{
			return _hour;
		}
		
		public function get minute():int
		{
			return _minute;
		}
		
		public function get second():Number
		{
			return _second;
		}
		
		public function get fractionalYear():Number
		{
			var daysInYear:int = ALDate.daysInYear( _year );
			var deltaDay:int = ALDate.date2JD( _year, _month, _day, _hour, _minute, _second ) - ALDate.date2JD( _year, 1, 1, 0, 0, 0 );
			var fy:Number = _year + deltaDay / daysInYear;
			return fy;
		}

		public function get fractionalHour():Number
		{
			if( !isSetFractionalHour )
			{
				isSetFractionalHour = true;
				_fractionalHour = _hour + _minute / 60.0 + _second / 3600.0;
			}
			return _fractionalHour;
		}
		
		public function get fractionalDay():Number
		{
			return fractionalHour / 24 + day;
		}
		
		public function clone():ALCalendarDate
		{
			return new ALCalendarDate( _year, _month, _day, _hour, _minute, _second );
		}
		
		public function equal( calendarDate:ALCalendarDate ):Boolean
		{
			if( calendarDate._year == _year && 
				calendarDate._month == _month &&
				calendarDate._day == _day &&
				calendarDate._hour == _hour &&
				calendarDate._minute == _minute &&
				calendarDate._second == _second 
			)
			{
				return true;	
			}
			return false;
		}
		
		public function toString( arcsecToFixed:int = 2 ):String
		{
			var month:String = _month < 10 ? "0"+_month : _month.toString();
			var day:String = _day < 10 ? "0"+_day : _day.toString();
			var hour:String = _hour < 10 ? "0"+_hour : _hour.toString();
			var minute:String = _minute < 10 ? "0" + _minute : _minute.toString();
			var second:String = _second < 10 ? "0" + _second.toFixed( arcsecToFixed ) : _second.toFixed( arcsecToFixed );
			return _year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
		}

	}
}